package com.qf.service.impl;

import com.qf.dao.CartDao;
import com.qf.dao.impl.CartDaoImpl;
import com.qf.domain.Cart;
import com.qf.domain.Goods;
import com.qf.service.CartService;
import com.qf.service.GoodsService;

import java.util.List;

/**
 * @author Administrator
 * @version v1.0
 * @date 2022/4/20
 */
public class CartServiceImpl implements CartService {
    CartDao cartDao = new CartDaoImpl();
    @Override
    public Cart findByUidAndGid(int uid, int pid) {
        return cartDao.findByUidANdGid(uid,pid);
    }

    @Override
    public void insert(Cart cart) {
        cartDao.insert(cart);
    }

    @Override
    public void updateCart(Cart cart) {
        cartDao.updatecart(cart);
    }

    @Override
    public List<Cart> findCardByUid(int uid) {

        List<Cart> carts =cartDao.findByid(uid);

        if(carts!=null&&carts.size()>0){
            GoodsService goodsService = new GoodsServiceImpl();
            for (Cart cart : carts) {
                Goods goods = goodsService.findById(cart.getPid());
                cart.setGoods(goods);
            }
        }

        return carts;
    }

    @Override
    public void deleteCart(int id, int pid) {
        cartDao.deleteCart(id,pid);
    }

    @Override
    public void clearCart(int id) {
        cartDao.clearCart(id);
    }


}
